<template>
  <div class="account-content-box">
    <div class="settings">
      <div class="settings_box">
        <div class="settings_title">{{ lang.password_settings_title }}</div>
        <div class="setPassword">
          <div class="setPassword_content">
            <form
              class="el-form el-form--default el-form--label-right el-form_style"
            >
              <div
                v-for="field in fields"
                :key="field.key"
                class="el-form-item is-error is-required asterisk-left el-form-item--label-right"
              >
                <div class="el-form-item__content">
                  <div class="el_input_box showInput fontP">
                    <div
                      class="el-input el-input-group el-input--suffix input_box_style otherBg el-input-group--prepend"
                    >
                      <div class="el-input-group__prepend">
                        <p class="head"></p>
                        <div class="icon_box">
                          <NuxtImg
                            src="/images/layout/icon-password.png"
                            style="width: 0.5rem; margin-right: 0.2rem"
                          />
                        </div>
                      </div>
                      <div class="el-input__wrapper" tabindex="-1">
                        <input
                          class="el-input__inner"
                          :type="field.showPsd ? 'text' : 'password'"
                          autocomplete="off"
                          tabindex="0"
                          :placeholder="field.placeholder"
                          v-model.trim="field.value"
                          @blur="valid(field)"
                        />
                        <div @click="field.showPsd = !field.showPsd">
                          <NuxtImg
                            v-if="field.showPsd"
                            src="/images/layout/icon-pwd-01.png"
                          />
                          <NuxtImg
                            v-else
                            src="/images/layout/icon-pwd-02.png"
                          />
                        </div>
                      </div>
                    </div>
                  </div>
                  <div v-if="field.isErr" class="el-form-item__error">
                    {{ field.errorText }}
                  </div>
                </div>
              </div>
            </form>
            <div class="btn" v-click-move @click="submit">
              <span>{{ lang.save_button }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const lang: any = getCurrentPageLang("setting");

const fields: any[] = reactive([
  {
    key: "old_pwd",
    value: "",
    isErr: false,
    placeholder: lang.old_password_placeholder,
    errorText: lang.old_pwd_required,
    showPsd: false,
  },
  {
    key: "new_pwd",
    value: "",
    isErr: false,
    placeholder: lang.new_password_placeholder,
    errorText: lang.new_pwd_required,
    showPsd: false,
  },
]);

function valid(field: any) {
  if (!field.value) {
    field.isErr = true;
    return false;
  }
  field.isErr = false;
  return true;
}

const submit = () => {
  for (let i = 0; i < fields.length; i++) {
    if (!valid(fields[i])) return;
  }
  showNotify({
    type: "success",
    message: "修改成功",
  });
};
</script>

<style scoped lang="scss">
.account-content-box {
  margin-top: 0.1rem;
}
.settings {
  display: flex;
  padding-top: 0.5rem;
  padding-bottom: 1.2rem;
  flex-direction: column;
  gap: 12px;
}
.settings_box {
  width: 100%;
  flex-shrink: 0;
}
.settings_title {
  margin-bottom: 0.25rem;
  font-size: 0.38rem;
  color: var(--theme-neutral1);
}
.setPassword_content {
  box-sizing: border-box;
  border-radius: 0.44rem;
}
.el-form {
  --el-form-label-font-size: var(--el-font-size-base);
  --el-form-inline-content-width: 220px;
}
.el-form_style .el-form-item {
  margin-bottom: 18px;
}
.el-form-item__content {
  display: block;
  position: relative;
}
.el_input_box {
  position: relative !important;
  border-radius: 0.2rem;
  border: 0.03rem solid var(--border-color);
}
.otherBg {
  background-color: #2c1d31;
}
.input_box_style {
  position: relative;
  display: grid;
  grid-template-columns: 13% 1fr;
  border-radius: 0.2rem;
}
.el-input-group {
  align-items: stretch;
  display: inline-flex;
  width: 100%;
}
.el-input {
  padding: 0 0.3rem;
  height: 1.1rem;
}
.el-input-group__prepend {
  width: 0.5rem;
  background: none;
  box-shadow: none;
  box-sizing: border-box;
  position: relative;
  font-size: 0.38rem;
  height: 100%;
  padding: 0;
  border-bottom-right-radius: 0;
  border-right: 0;
  border-top-right-radius: 0;
  box-shadow: 1px 0 0 0 var(--el-input-border-color) inset,
    0 1px 0 0 var(--el-input-border-color) inset,
    0 -1px 0 0 var(--el-input-border-color) inset;
  display: flex;
  align-items: center;
}
.el-input-group__prepend:before {
  content: "";
  position: absolute;
  right: -0.3rem;
  width: 0.04rem;
  height: 0.6rem;
  background: var(--border-color);
  border-radius: 0.2rem;
}
.icon_box {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  position: relative;
}
.el_input_box .input_box_style .el-input__wrapper {
  box-shadow: none;
  width: calc(100% - 1rem);
  margin-left: 0.7rem;
}
.el-form-item.is-error .el-input__wrapper,
.el-form-item.is-error .el-input__wrapper.is-focus,
.el-form-item.is-error .el-input__wrapper:focus,
.el-form-item.is-error .el-input__wrapper:hover,
.el-form-item.is-error .el-select__wrapper,
.el-form-item.is-error .el-select__wrapper.is-focus,
.el-form-item.is-error .el-select__wrapper:focus,
.el-form-item.is-error .el-select__wrapper:hover,
.el-form-item.is-error .el-textarea__inner,
.el-form-item.is-error .el-textarea__inner.is-focus,
.el-form-item.is-error .el-textarea__inner:focus,
.el-form-item.is-error .el-textarea__inner:hover {
  box-shadow: 0 0 0 1px var(--el-color-danger) inset;
}
.el-input-group--prepend > .el-input__wrapper,
.el-input-group__append {
  border-bottom-left-radius: 0;
  border-top-left-radius: 0;
}
.input_box_style .el-input__wrapper {
  background: transparent;
  border-radius: 0.2rem;
}
.el-input__wrapper {
  align-items: center;
  background-color: var(--el-input-bg-color, var(--el-fill-color-blank));
  background-image: none;
  border-radius: var(--el-input-border-radius, var(--el-border-radius-base));
  box-shadow: 0 0 0 1px var(--el-input-border-color, var(--el-border-color))
    inset;
  cursor: text;
  display: inline-flex;
  flex-grow: 1;
  justify-content: center;
  transform: translateZ(0);
  transition: var(--el-transition-box-shadow);
}
.el_input_box .input_box_style .el-input__wrapper input {
  height: 100%;
  --el-input-inner-height: 0.3rem;
  color: var(--theme-neutral1);
  width: 100%;
  background-color: transparent;
  padding-right: 0.2rem;
}
.btn {
  margin: 0.2rem auto;
  width: 100%;
  display: flex;
  justify-content: center;
  height: 1.2rem;
  align-items: center;
  background: linear-gradient(360deg, #e150a4 0%, #e66fc8 81%);
  border-radius: 0.3rem;
}
.btn span {
  width: 100%;
  height: 100%;
  font-size: var(--font-title);
  color: var(--theme-neutral1);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.el-form-item__error {
  color: #f56c6c;
  font-size: 12px;
  left: 0;
  line-height: 1;
  padding-top: 2px;
  position: absolute;
  top: 100%;
}
</style>
